class Photo < ActiveRecord::Base
  def photo=(image)
  	self.name = base_part_of(image.original_filename)
  	self.content_type = image.content_type
  	self.data = image.read
  end
  
  protected 
  def base_part_of(file_name)
  	name = File.basename(file_name)
  	name.gsub(/[^\w._-]/, '')
  end
end
